package com.person.commons.utils;

import java.util.Date;
import java.util.List;



public class JstlUtils {


	
	/**
	 * 将字符串截短，取前n个字符，英文算半个字符。
	 * 
	 * @param orignalString
	 *            原字符串
	 * @param length
	 *            长度
	 * @param chopedString
	 *            超过部分的表示字符串
	 * @return 截取的字符串
	 */
	public static String chop(String orignalString, int length,
			String chopedString) {
		// orignalString = orignalString.replaceAll("<(.*?)>", "");
		// System.out.println(orignalString);
		if (orignalString == null || orignalString.length() == 0) {
			return orignalString;
		}
		// orignalString = orignalString.replaceAll(" ", " ");
		if (orignalString.length() < length) {
			return orignalString;
		}
		StringBuffer buffer = new StringBuffer(length);
		length = length * 2;
		int count = 0;
		int stringLength = orignalString.length();
		int i = 0;
		for (; count < length && i < stringLength; i++) {
			char c = orignalString.charAt(i);
			if (c < '\u00ff') {
				count++;
			} else {
				count += 2;
			}
			buffer.append(c);
		}
		if (i < stringLength) {
			buffer.append(chopedString);
		}
		/**
		 * String s = buffer.toString(); int a = REUtil.getREGroupCount(s, "(<div
		 * .*?>)"); int b = REUtil.getREGroupCount(s, "(</div)"); //
		 * System.out.println("a==" + a + ",b==" + b); //
		 * System.out.println(buffer.toString()); for (int j = a - b; j > 0;
		 * j--) { buffer.append("</div>"); } //
		 * System.out.println("---------------------------"); //
		 * System.out.println(buffer.toString());
		 */
		return buffer.toString();
	}
}
